package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.CompanyAddrDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CompanyAddress;
import com.itheima.service.CompanyAddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = CompanyAddrService.class)
@Transactional
public class CompanyAddrServiceImpl implements CompanyAddrService {
    @Autowired
    CompanyAddrDao companyAddrDao;

    @Override
    public List<String> findMap() {
        return companyAddrDao.findMap();
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {

        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        //条件查询--模糊查询
        if (queryString != null) {
            queryString = "%" + queryString + "%";
        }

        PageHelper.startPage(currentPage, pageSize);
        Page<CompanyAddress> page = companyAddrDao.finPageByCondition(queryString);
        List<CompanyAddress> addressList = page.getResult();
        long total = page.getTotal();

        return new PageResult(total, addressList);
    }

    @Override
    public void addCompanyAddr(CompanyAddress companyAddress) {
        companyAddrDao.addCompanyAddr(companyAddress);
    }

    @Override
    public void deleteCompantAddr(Integer id) {
        companyAddrDao.deleteCompantAddr(id);
    }

    @Override
    public List<String> findAllAddr() {
        return companyAddrDao.findAllAddr();
    }
}
